<?php

/**
 * Created by PhpStorm.
 * User: li
 * Date: 15-10-18
 * Time: 下午11:52
 */
class Search extends MY_Pc_Api_Controller
{
    function __construct(){
        parent::__construct();
    }


    /**
     * 搜索
     *
     * @return json
     */
    function do_search(){
        //todo: 第二版需要优化算法
        $key = $this->input->get('key');
        $type = $this->input->get('type');
        $condition = array('is_del'=>0);
        $page = $this->input->get('page');
        $page = $page>0?$page:1;
        $offset = ($page-1)*$this->_page_size;
        $options = array(
            'limit' =>  array($offset,$this->_page_size)
        );
        if(!$key)
            $this->json_response(false);
        if(!$type){
            $this->load->model('activities/Activities_model');
            $result = $this->Activities_model->fetch_array($condition,'*',$options);
        }else{
            //规范模型命名  文章模型、活动模型
            $model_name = $type=='article'?'Article_model':'Activities_model';
            $path  = $type=='article'?'':'activities';
            $this->load->model($path.'/'.$model_name);
            $result = $this->$model_name->fetch_array($condition,'*',$options);
        }
        if($result===null)
            $this->json_response(false,'','没有找到 '.$key.' 相关信息');
        $this->json_response(false,$result);
    }
}